<style lang="less">
  @import '../../styles/common.less';
  @import '../../tables/components/table.less';
</style>

<template>
  <div>
    <Row :gutter="10">
      <Card>
        <div class="table-head">
          <div class="left">
            <Select v-model="typeSelectid" :transfer="true" @on-change="onChangeTypeSelect">
              <Option v-for="item in typeSelect" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </div>
        </div>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data"></Table>
        </Row>
      </Card>
    </Row>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../../libs/util';
  import Utils from '../../../libs/mod.utils';
  import String from '../../../libs/mod.string';
  import Modal from '../../../libs/mod.Modal';
  export default {
    components: {},
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        id: '',
        typeSelectid: 'all',
        typeSelect: [
          {
            id: 'all',
            name: '全部',
          },
        ],
        columns: [
          {
            key: 'type',
            title: '类型',
            align: 'center',
          },
          {
            key: 'num',
            title: '户数',
            align: 'center',
          },
        ],
        data: [
          {
            type: '多次采集至信息完善',
            num: 0,
          },
          {
            type: '信息未完善',
            num: 0,
          },
          {
            type: '首次积极配合',
            num: 0,
          },
          {
            type: '首次拜访不在家',
            num: 0,
          },
          {
            type: '多次拜访不在家',
            num: 0,
          },
          {
            type: '首次拜访拒绝配合',
            num: 0,
          },
          {
            type: '多次拜访拒绝配合',
            num: 0,
          },
          {
            type: '未拜访',
            num: 0,
          },
          {
            type: '无人居住',
            num: 0,
          },
          {
            type: '总户数',
            num: 0,
          },
        ],
      };
    },
    mounted () {
      var _this = this;
      _this.getCommunityTreeList();
      _this.getData();
    },
    methods: {
      onChangeTypeSelect: function (val) {
        var _this = this;
        _this.typeSelectid = val;
        _this.getData();
      },
      getData () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          id: _this.typeSelectid == 'all' ? '' : _this.typeSelectid,
        };
        var params = {
          url: '/sd/social-repo/statistics',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || {};
            var data = [
              {
                type: '多次采集至信息完善',
                num: _data.many_perfect > 0 ? _data.many_perfect : 0,
              },
              {
                type: '信息未完善',
                num: _data.imperfect > 0 ? _data.imperfect : 0,
              },
              {
                type: '首次积极配合',
                num: _data.perfect_active > 0 ? _data.perfect_active : 0,
              },
              {
                type: '首次拜访不在家',
                num: _data.first_imperfect > 0 ? _data.first_imperfect : 0,
              },
              {
                type: '多次拜访不在家',
                num: _data.many_imperfect > 0 ? _data.many_imperfect : 0,
              },
              {
                type: '首次拜访拒绝配合',
                num: _data.first_reject > 0 ? _data.first_reject : 0,
              },
              {
                type: '多次拜访拒绝配合',
                num: _data.many_reject > 0 ? _data.many_reject : 0,
              },
              {
                type: '未拜访',
                num: _data.not_visiting > 0 ? _data.not_visiting : 0,
              },
              {
                type: '无人居住',
                num: _data.unpeople > 0 ? _data.unpeople : 0,
              },
              {
                type: '总户数',
                num: _data.total > 0 ? _data.total : 0,
              }
            ];
            _this.data = data;
          } else {
            _this.$Message.error('统计信息失败!');
          }
        }
      },
      // 获取小区
      getCommunityTreeList: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/sd/social-repo/community/getCommunityTreeList',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var typeSelect = [];
            for (var k in _data) {
              if (!_data[k]) {
                continue;
              }
              var obj = {
                id: _data[k].id,
                name: _data[k].name,
              };
              typeSelect.push(obj);
            }
            _this.typeSelect.push(...typeSelect);
          } else {
            _this.$Message.error('查询小区信息失败!');
          }
        }
      },
    }
  };
</script>
